import ImageCompressor from 'image-compressor.js'

const compressImage = async (file: any) => {
    var imageCompressor = new ImageCompressor()
    return new Promise((resolve, reject) => {
        imageCompressor
        .compress(file, { quality: 0.6, maxHeight: 100, maxWidth: 100 })
        .then((result) => {
            resolve(result)
        })
        .catch((err) => {
            reject(err)
        })
    })
}

const blobToBase64 = (blob: any) => {
    return new Promise((resolve, reject) => {
      const reader = new FileReader()
      reader.onloadend = () => {
        resolve(reader.result)
      }
      reader.onerror = reject
      reader.readAsDataURL(blob)
    })
}

export {compressImage, blobToBase64}